<template>
  <div>
    <h2>登录页面</h2>
    用户名<input type="text" v-model="name">
    <button @click="sub">登录</button>
  </div>
</template>

<script>
export default {
  data(){
    return{
      name:''
    }
  },
  methods:{
    sub:function(){
      let formdata=new FormData();
      formdata.append('name',this.name)
      this.axios({
        url:'http://127.0.0.1:8000/app01/login/',
        method:'post',
        data:formdata
      }).then(res=>{
        if(res.data.code==1000){
          // 将数据保存到本地
          sessionStorage.setItem('uid',res.data.data);
          // 完成跳转
          this.$router.push({
            name:'List'
          })
        }else{
          alert(res.data.msg);
        }

      })
    }
  }
}
</script>

<style>

</style>
